package cn.java;

import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class LockDemo {
    static ReentrantLock reentrantLock = new ReentrantLock();

    static ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();

    Exchanger<String> exchanger = new Exchanger<>();

    CyclicBarrier cyclicBarrier = new CyclicBarrier(1);

    CountDownLatch countDownLatch = new CountDownLatch(1);

    Semaphore semaphore = new Semaphore(1);

    Phaser phaser = new Phaser();


    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new LockDemo1(),"00001");
        Thread thread2 = new Thread(new LockDemo1(),"00002");
        thread1.start();
        thread2.start();
        Thread.sleep(1000);
        System.out.println();
        Thread thread3 = new Thread(new LockDemo1(),"00003");
        thread3.start();
        System.out.println();
        ReentrantReadWriteLock.ReadLock readLock = reentrantReadWriteLock.readLock();
        readLock.lock();
    }

    public static void fun(){
        reentrantLock.lock();
        System.out.println("11");
        System.out.println("22");
        reentrantLock.unlock();
    }

     static class LockDemo1 implements Runnable {
        @Override
        public void run() {
            LockDemo.fun();
        }
    }

}
